import time
from symbol import yield_expr

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class TestCase():

    def driver(self):
        driver=webdriver.Chrome()
        driver.get('https://www.so.com/')
        driver.maximize_window()
        yield driver
        time.sleep(3)
        driver.quit()


    @pytest.fixture(scope='class')
    def test_01(self,driver):

        #第一种方法找到搜索框
        driver.find_emement(By.ID,'input').send_keys('我在做软件测试')
        time.sleep(5)

        #第二种方法找到搜索框
        driver.find_emement(By.NAME, 'q').send_keys('我在做软件测试')
        time.sleep(5)

        #点击搜索
        sousuo=driver.find_emement(By.ID, 'search-button').click()
        WebDriverWait(driver,0.5,20).until(EC.presence_of_element_located(sousuo))

        dy=driver.find_emement(By.XPATH,'/html/body/div[6]/div[1]/div[1]/div[1]/dl/dd/a[1]')
        print("断言：",dy)
        assert "测试" in dy

        # /html/body/div[6]/div[3]/div[1]/a[1]
        #翻到下一页
        driver.find_emement(By.XPATH, '/html/body/div[6]/div[3]/div[1]/a[1]')

        #翻到下一页
        try:
            driver.switch_to.window(driver.window_handles[-1])
        except Exception as e:
            print('未翻到下一页')
            driver.save_screenshot(driver, 'aa.png')

